/*
 * @Author: Simon 1958058172@qq.com
 * @Date: 2025-08-11 14:47:22
 * @LastEditors: Simon 1958058172@qq.com
 * @LastEditTime: 2025-08-11 15:09:01
 * @FilePath: \java.1212\csdn\jihe\li03\Test.java
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package csdn.jihe.li03;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Test {
    public static void main(String[] args) {
        Collection<String> collection=new ArrayList<>();
        collection.add("hello");
        collection.add("world");
        collection.add("!");
        //遍历1--for+toArray
        Object[] arr=collection.toArray();
        for(int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }

        //遍历2--迭代器
        Iterator<String> iterator= collection.iterator();//获取迭代器对象
        while (iterator.hasNext()) {
            String string=iterator.next();
            System.out.println(string);
            
        }

        //遍历3--增强for循环
        for(Object obj:collection.toArray()){
            System.out.println(obj);
        }



    }
}
